package com.whfc.emp.redis.impl;

import com.whfc.emp.redis.XionganApiTokenRedisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021-03-15 19:48
 */
@Repository
public class XionganApiTokenRedisDaoImpl implements XionganApiTokenRedisDao {

    private static final String TOKEN_KEY = "%s:access_token";

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void put(String redisKey,String accessToken, Long expireTime) {
        String key = String.format(TOKEN_KEY,redisKey);
        redisTemplate.opsForValue().set(key, accessToken, expireTime, TimeUnit.SECONDS);
    }

    @Override
    public String get(String redisKey) {
        String key = String.format(TOKEN_KEY,redisKey);
        return redisTemplate.opsForValue().get(key);
    }
}
